|
|
|
|
|
|
|
This window works just like any source code editor: You can use the Tab key to indent with spaces, the Enter key will add a new line, and so on. |
|
|
|
|
|
|
|
|
It is very important that you always set the Name property of a control prior to writing code. If you write the code first and then change the Name property of the control, the code is disconnected from the control and deposited into the General section of the form. |
|
|
|
 |
|
|
|
|
TIP Set the Name property of all your controls prior to writing source code for them. |
|
|
|
|
|
|
|
|
Breakdown of an Event Procedure |
|
|
|
|
|
|
|
|
Event procedures are bits of code that run when something happens to a form or a control. An event procedure must be defined in a very specific format. In the code window in Figure 5.1, you see a declaration for the Form_Load() event procedure. Lets break this down into its constituent parts (see Table 5.1). |
|
|
|
|
| Table 5.1 Breakdown of an Event Procedure. | | Part | Description | | Private Sub | This declares a new event procedure thats private to this form. | | Form_ | Form is a generic name given to every form. Even if the name of the form is frmCust, it will still be called Form_Load(). This name will change for controls, because it uses the control name followed by an underscore and then the event name. | | Load | This is the event name thats invoked when the form is loaded by Windows or by your source code. | | <blank lines> | In between the first line and End Sub is where youll write your source code. | | End Sub | This marks the end of the event procedure. |
|
|
|
|
|
|
The Form_Load() event procedure is normally used to set default values for the form. For example, you can change the position of the form or initialize some of the other properties of the form. |
|
|
|
|
|
|
|
|
Examples Filename: Employee.frm |
|
|
|
|
|